﻿using System;
using System.Collections.Generic;
using IFRS.DataAccess.DAL;
using IFRS.Models;
using IFRS.Web;
using IFRS_Global;

public partial class IFRS_WIN05_3V : PageBase
{
    #region === Event ===

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewMenu();
            BindControl();
            BindData();
        }
        else
            ClientScript.RegisterHiddenField("isPostBack", "1");
    }
    protected void btnCANCEL_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/IFRS/WIN05_1S.aspx");
    }

    #endregion

    #region === Method ===

    private void ViewMenu()
    {
        MenuTitleBar = Resources.ifrsMenu.WIN05_3V;
    }
    private void BindControl()
    {
        ddlCreditLevel.SetData(DDL_TYPE.CreditLevel, string.Empty, false, true);
        ddlContractLoanType.SetData(DDL_TYPE.ContractLoanType, string.Empty, false, true);

        txtStatus.Text = Resources.ifrsField.CREATE;
        SetControlReadOnly(form_control);
    }
    private void BindData()
    {
        if (Convert.ToString(Request.QueryString["id"]) != string.Empty)
        {
            var id = Convert.ToInt32(Request.QueryString["id"]);
            var dt = new SPR_NOID().SEARCH_BYID(id);
            if (dt != null && dt.Rows.Count > 0)
            {
                var list = new List<NOID>();
                ConvertHelper.ConvertDataTableToObject(dt, list);

                txtTransactionDate.Text = list[0].TransactionDate.DateToString();

                txtGLAccountCode.Text = list[0].GLAccount;
                hddCostCenter.Value = list[0].CostCenter;
                txtCostCenter.Text = list[0].COST_CENTER_NM;
                txtUnpaidAmount.Text = list[0].UnpaidAmount.DecimalToString();
                txtCurrencyCode.Text = list[0].CurrencyCode;
                ddlCreditLevel.SelectedValue = list[0].CreditLevelID.IntToString();
                hddLoanObjectiveID.Value = list[0].LoanObjectiveID;
                txtLoanObjectiveID.Text = list[0].CBT_DESC_LEV1;
                ddlContractLoanType.SelectedValue = list[0].ContractLoanTypeID.IntToString();
                txtReservedAmount.Text = list[0].ReservedAmount.DecimalToString();

                txtStatus.Text = list[0].IsConfirmed == true ? Resources.ifrsField.CONFIRM : Resources.ifrsField.CREATE;
            }
        }
    }

    #endregion
}